<template>
  <div class="edit">
    <Header>
      <slot> 编辑地址 </slot>
    </Header>
    <section>
      <van-address-edit :area-list="areaList" show-set-default @save="onSave" />
    </section>
    <Tabbar></Tabbar>
  </div>
</template>

<script>
import Header from "@/components/Path/Header.vue";
import Tabbar from "@/components/Tabbar.vue";
import { Toast } from "vant";
import http from "@/common/request";
export default {
  components: { Header, Tabbar },
  data() {
    return {
      areaList: {
        province_list: {
          110000: "北京市",
          120000: "天津市",
        },
        city_list: {
          110100: "北京市",
          120100: "天津市",
        },
        county_list: {
          110101: "东城区",
          110102: "西城区",
          120101: "塘沽区",
          // ....
        },
      }
    };
  },
  methods: {
    // 保存数据时触发
  async onSave(content) {
    content.isDefault = content.isDefault?1:0;
    // console.log(content);
    let res =await http.$axios({
      url:'/api/addadress',
      method:'post',
      data:{
        content
      },
      headers:{
        token:true
      }
    })
    console.log(res);
    if(res.success){
      this.$router.push({
        path:'/path'
      })
    }
  },
  }
};
</script>

<style scoped>
.edit {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}
section {
  flex: 1;
  overflow: hidden;
}
.tabbar {
  border-top: 2px solid #aaa;
}
Header {
  font-size: 18px;
}
::v-deep .van-button {
  background-color: rgba(210, 0, 0, 1);
}
</style>